import 'package:flutter/material.dart';
import 'package:getxdemo/get/get_commen_view.dart';
import 'package:getxdemo/route/routers.dart';
import 'package:getxdemo/ui/page/splash_page/controller.dart';
import 'package:get/get.dart';
import 'package:getxdemo/utils/sp_util.dart';

import '../../../res/r.dart';
import '../../../res/string.dart';
import 'package:dio/dio.dart';

class SplashPage extends GetCommonView<SplashController> {
  const SplashPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        body: Column(
          children: [
            AnimatedOpacity(
              opacity: controller.opacity,
              duration: const Duration(milliseconds: 500),
              child: Container(
                margin: const EdgeInsets.only(top: 120),
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Image.asset(
                      R.assetsImagesApplication,
                      fit: BoxFit.fitWidth,
                      width: 110,
                      height: 110,
                    ),
                    Container(
                      margin: const EdgeInsets.only(top: 16),
                      child: Text(Str.appName.tr),
                    )
                  ],
                ),
              ),
              onEnd: () {
                bool isLogin = SPUtil.getUserEntity() != null;
                Get.offAllNamed(isLogin ? Routes.homePage : Routes.loginPage);
              },
            ),
          ],
        ));
  }

  Container animatedButton() {
    return Container(
      color: Colors.red,
      child: TextButton(
        style: const ButtonStyle(
            backgroundColor: MaterialStatePropertyAll<Color>(Colors.white)),
        onPressed: () {
          controller.rest();
        },
        child: const Text("执行动画"),
      ),
    );
  }
}
